package util;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ResourceBundle;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

import modelUtil.Configuracion;
import modelUtil.Util;
import AccionBoton.AccionCambiarTextoCreditos;
import AccionBoton.AccionCerrar;
import AccionBoton.AccionCerrarCruz;
import AccionBoton.AccionFocoCreditos;
import AccionBoton.AccionRatonCreditosAux;
import AccionBoton.AccionSeleccionarMostrarCreditos;
import AccionBoton.accionRaton;

public class PaginaCreditosAux extends JDialog{

	private JFrame _frame;
    private BotonPersonalizado jButton1;
    private BotonPersonalizado jButton2;
    private BotonPersonalizado jButton3;
    private BotonPersonalizado jButton4;
    private BotonPersonalizado jButton5;
    private BotonPersonalizado seleccionado;
    private JEditorPane jEditorPane1 = new JEditorPane();
    private JCheckBox check;
    
    private JPanel panel1=new JPanel();
    private JPanel panel2=new JPanel();
    private JPanel panel3=new JPanel();
    private JPanel panel4=new JPanel();
	private JPanel Izq = new JPanel();
	private JPanel Drcha = new JPanel();
	private GridBagLayout grid = new GridBagLayout();
	private TransicionBotones policy;
    /**
     * 
     * @param frame
     */
    public PaginaCreditosAux(JFrame frame) {
		_frame = frame;
		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();
		this.setPreferredSize(new Dimension(700,500));
		this.setBackground(Color.white);
        initComponents();
        panel1.setBackground(Color.white);
        panel2.setBackground(Color.white);
        panel3.setBackground(Color.white);
        panel4.setBackground(Color.white);
        Izq.setBackground(Color.white);
        
        Vector<Component> order = new Vector<Component>(7);
        order.add(jButton1);
        order.add(jButton2);
        order.add(jButton3);
        order.add(jButton4);
        order.add(check);

        
    	//_frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
       jButton1.doClick();
       this.addWindowFocusListener(new WindowAdapter() {
    	    public void windowGainedFocus(WindowEvent e) {
    		    jButton1.requestFocusInWindow(); 
    	    }
    	});
       this.setFocusable(true);
       this.addComponentListener(new AccionCerrarCruz(this,_frame));
       policy = new TransicionBotones(order);
       this.setFocusTraversalPolicy(policy);
       this.setVisible(true);
		this.pack();
        this.repaint();
    }
    
    

    private void initComponents() {
    
    	GridBagLayout grid = new GridBagLayout();
    	GridBagConstraints cons = new GridBagConstraints();
    	this.setLayout(grid);
    	
    	crearPanel1();
    	crearPanel2();
    	crearPanel3();
    	crearPanel4();
    	
    	cons.gridheight = 1;
    	cons.gridwidth = 1;
    	cons.fill = GridBagConstraints.BOTH;
    	cons.gridx = 0;
    	cons.gridy = 0;
    	grid.addLayoutComponent(panel1, cons);
    	this.add(panel1);
    	cons.gridy = 1;
    	grid.addLayoutComponent(panel2, cons);
    	this.add(panel2);
    	cons.gridy = 2;
    	grid.addLayoutComponent(panel3, cons);
    	this.add(panel3);
    	cons.gridy = 3;
    	cons.insets = new Insets(20, 0, 0, 0);

    	grid.addLayoutComponent(panel4, cons);
    	this.add(panel4);

    	
    }
	//Crea el panel superior con el logo
    public void crearPanel1(){
    	
    	FlowLayout flow = new FlowLayout();
    	panel1.setLayout(flow);
    	flow.setAlignment(FlowLayout.CENTER);
        ImageIcon Logo = new ImageIcon("lib/logosintic/intic.gif");
        int anchoLogo = Logo.getIconWidth();
        int altologo = Logo.getIconHeight();
        Dimension dimensiones = Toolkit.getDefaultToolkit().getScreenSize();
        double factorEscala = (double) (altologo/(double)(500/8));
        Image scala = Logo.getImage().getScaledInstance((int) Math.floor((float)(anchoLogo/factorEscala)), (int)(500/8), Image.SCALE_DEFAULT);
        Logo = new ImageIcon(scala);
        JLabel et = new JLabel();
        et.setIcon(Logo);
        flow.addLayoutComponent("logo", et);
        panel1.add(et);
    	
    	
    }
    
    //Crea el panel donde están situados los botones y el texto
    public void crearPanel2(){
    	
		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();
    	//panel2.setSize(new Dimension(screenSize.width, screenSize.height-500));
    	//panel2.setMinimumSize(new Dimension(screenSize.width, screenSize.height-600));

    	//panel2.setPreferredSize(new Dimension(screenSize.width, screenSize.height-600));
    	panel2.setPreferredSize(new Dimension(700, 500/2));
    	//panel2.setSize(new Dimension(screenSize.width, 600));

		
    	grid = new GridBagLayout();
    	GridBagConstraints cons = new GridBagConstraints();
    	panel2.setLayout(grid);
    	cons.gridheight = 1;
    	cons.gridwidth = 1;
    	cons.fill = GridBagConstraints.BOTH;
    	
    	 jButton1 = Util.BotonImagen(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_boton_creditos_intic"), "");
         jButton1.getLabelTexto().setFont(new Font( "Dialog",Font.PLAIN,22));
         jButton1.setBorder(new LineBorder(Color.black,3));
         jButton1.setBackground(Color.white);
         jButton1.addActionListener(new AccionCambiarTextoCreditos(jEditorPane1,ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("Creditos_intic")));
         


         ImageIcon Logo = new ImageIcon("lib/logosintic/orange.gif");
         int anchoLogo = Logo.getIconWidth();
         int altologo = Logo.getIconHeight();
         double factorEscala = (double) (altologo/((double)((int)500/8)));

         Image scala = Logo.getImage().getScaledInstance((int) Math.floor((float)(anchoLogo/factorEscala)), (int)Math.floor(500/8), Image.SCALE_DEFAULT);
         Logo = new ImageIcon(scala);
         jButton2 = Util.BotonImagen("","");


         jButton2.getLabelImagen().setIcon(Logo);
         jButton2.addActionListener(new AccionCambiarTextoCreditos(jEditorPane1,ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("Creditos_orange")));

         
         Logo = new ImageIcon("lib/logosintic/imedir.gif");
         anchoLogo = Logo.getIconWidth();
         altologo = Logo.getIconHeight();
         factorEscala = (double) (altologo/((double)((int)500/8)));

         scala = Logo.getImage().getScaledInstance((int) Math.floor((float)(anchoLogo/factorEscala)), (int)Math.floor(500/8), Image.SCALE_DEFAULT);
         Logo = new ImageIcon(scala);
         jButton3 = Util.BotonImagen("","");


         jButton3.getLabelImagen().setIcon(Logo);
         jButton3.addActionListener(new AccionCambiarTextoCreditos(jEditorPane1,ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("Creditos_imedir")));


         Logo = new ImageIcon("lib/logosintic/avanza.png");
         anchoLogo = Logo.getIconWidth();
         altologo = Logo.getIconHeight();
         factorEscala = (double) (altologo/((double)((int)500/20)));


         scala = Logo.getImage().getScaledInstance((int) Math.floor((float)(anchoLogo/factorEscala)), (int)Math.floor(500/20), Image.SCALE_DEFAULT);
         Logo = new ImageIcon(scala);
         jButton4 = Util.BotonImagen("","");


         jButton4.getLabelImagen().setIcon(Logo);
         jButton4.addActionListener(new AccionCambiarTextoCreditos(jEditorPane1,ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("Creditos_avanza")));

         
     	// jButton1.setPreferredSize(new Dimension((int)screenSize.getWidth()/4,100));
     	// jButton2.setPreferredSize(new Dimension((int)screenSize.getWidth()/4,100));
     	// jButton3.setPreferredSize(new Dimension((int)screenSize.getWidth()/4,100));
     	// jButton4.setPreferredSize(new Dimension((int)screenSize.getWidth()/4,100));
//         jEditorPane1.setPreferredSize(new Dimension(3*((int)screenSize.getWidth()/4),2*((int)screenSize.getHeight()/3)));

     	 
     	 jButton1.setPreferredSize(new Dimension((int)700/4,(int)500/11));
     	 jButton2.setPreferredSize(new Dimension((int)700/4,(int)500/11));
     	 jButton3.setPreferredSize(new Dimension((int)700/4,(int)500/11));
     	 jButton4.setPreferredSize(new Dimension((int)700/4,(int)500/11));
         //jEditorPane1.setPreferredSize(new Dimension(400,400));
         jEditorPane1.setPreferredSize(new Dimension(2*((int)700/3)-50,(int)500/3));
    	 //jEditorPane1.setFocusable(true);
    	 //jEditorPane1.addFocusListener(new AccionFocoCreditos(jEditorPane1));



         jButton2.setBorder(new LineBorder(Color.black,3));
         jButton3.setBorder(new LineBorder(Color.black,3));
         jButton4.setBorder(new LineBorder(Color.black,3));
         
    	 jButton1.setColorMouseOver(Color.LIGHT_GRAY);
    	 jButton2.setColorMouseOver(Color.LIGHT_GRAY);
    	 jButton3.setColorMouseOver(Color.LIGHT_GRAY);
    	 jButton4.setColorMouseOver(Color.LIGHT_GRAY);
    	 
    	 jButton1.setColorPresionado(Color.GRAY);
    	 jButton2.setColorPresionado(Color.GRAY);
    	 jButton3.setColorPresionado(Color.GRAY);
    	 jButton4.setColorPresionado(Color.GRAY);
    	 
         //jButton1.addMouseListener(new AccionRatonCreditosAux(jButton1,jButton1.getPresionado()));
         //jButton2.addMouseListener(new AccionRatonCreditosAux(jButton2,jButton2.getPresionado()));
         //jButton3.addMouseListener(new AccionRatonCreditosAux(jButton3,jButton3.getPresionado()));
         //jButton4.addMouseListener(new AccionRatonCreditosAux(jButton4,jButton4.getPresionado()));
         
    	 jButton1.setMnemonic(KeyEvent.VK_I);
    	 jButton1.setFocusable(true);
    	 jButton1.addFocusListener(new AccionFocoCreditos(jButton1));
    	 jButton1.getLabelTexto().getAccessibleContext().setAccessibleName(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_creditos") + ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_intic"));
    	 jButton1.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_creditos") + ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_intic"));
    	 
    	 jButton2.setMnemonic(KeyEvent.VK_O);
    	 jButton2.setFocusable(true);
    	 jButton2.addFocusListener(new AccionFocoCreditos(jButton2));
    	 jButton2.getLabelTexto().getAccessibleContext().setAccessibleName(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_creditos") + ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_orange"));
    	 jButton2.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_creditos") + ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_orange"));

    	 jButton3.setMnemonic(KeyEvent.VK_L);
    	 jButton3.setFocusable(true);
    	 jButton3.addFocusListener(new AccionFocoCreditos(jButton3));
    	 jButton3.getLabelTexto().getAccessibleContext().setAccessibleName(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_creditos") + ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_imedir"));
    	 jButton3.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_creditos") + ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_imedir"));

    	 
    	 jButton4.setMnemonic(KeyEvent.VK_P);
    	 jButton4.setFocusable(true);
    	 jButton4.addFocusListener(new AccionFocoCreditos(jButton4));
    	 jButton4.getLabelTexto().getAccessibleContext().setAccessibleName(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_creditos") + ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_avanza"));
    	 jButton4.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_creditos") + ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_avanza"));
    	 
     
         jEditorPane1.setFont(new Font( "Dialog",Font.PLAIN,18));
         jEditorPane1.setContentType("text/html");
         jEditorPane1.getAccessibleContext().setAccessibleName(jEditorPane1.getText());
    	 jEditorPane1.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_texto_creditos"));

         cons.gridx = 0;
         cons.gridy = 0;
         grid.addLayoutComponent(jButton1, cons);
         panel2.add(jButton1);
         cons.insets = new Insets(10,0,0,0);  //top padding
         cons.gridy = 1;
         grid.addLayoutComponent(jButton2, cons);
         panel2.add(jButton2);
         cons.gridy = 2;
         grid.addLayoutComponent(jButton3, cons);
         panel2.add(jButton3);
         cons.gridy = 3;
         grid.addLayoutComponent(jButton4, cons);
         panel2.add(jButton4);
         

     	cons.gridheight = 4;
    	cons.gridwidth = 1;
    	cons.fill = GridBagConstraints.BOTH;
    	cons.gridx = 1;
    	cons.gridy = 0;
        cons.insets = new Insets(0,20,0,0);  //top padding
        jEditorPane1.setEditable(false);
        JScrollPane scroll = new JScrollPane(jEditorPane1);
        scroll.setPreferredSize(new Dimension(2*((int)700/3)-50,(int)500/3));

        scroll.setBorder(null);

        grid.addLayoutComponent(scroll, cons);
    	panel2.add(scroll);

    	
    }
    
    //Crea el panel donde están situados los dos dibujos
    public void crearPanel3(){
    	
		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();
    	FlowLayout flow = new FlowLayout();
    	panel3.setLayout(flow);
        ImageIcon ninho = new ImageIcon("lib/logosintic/dibujo.jpg");
        ImageIcon ninha = new ImageIcon("lib/logosintic/dibujo2.jpg");
        Image scala3 = ninho.getImage().getScaledInstance((int) Math.floor((float)(69*screenSize.width/1000)), (int) Math.floor((float)(111*screenSize.height/1000)), Image.SCALE_DEFAULT);
        ninho = new ImageIcon(scala3);
        scala3 = ninha.getImage().getScaledInstance((int) Math.floor((float)(69*screenSize.width/1000)), (int) Math.floor((float)(111*screenSize.height/1000)), Image.SCALE_DEFAULT);
        ninha = new ImageIcon(scala3);
        
        JLabel etiqueta1 = new JLabel();
        etiqueta1.setIcon(ninho);
        
        JLabel etiqueta2 = new JLabel();
        etiqueta2.setIcon(ninha);
        flow.setAlignment(FlowLayout.CENTER);
        flow.addLayoutComponent("etiqueta1", etiqueta1);
        flow.setHgap((int)700/6);
        //flow.setHgap(400);
        panel3.add(etiqueta1);
        panel3.setPreferredSize(new Dimension(screenSize.width,(int) Math.floor((float)(12*screenSize.width/100))));
        flow.addLayoutComponent("etiqueta2", etiqueta2);
        panel3.add(etiqueta2);
        JLabel version = new JLabel(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_version_intic"));
        version.setFont(version.getFont().deriveFont(Font.BOLD, 14));
        version.setPreferredSize(new Dimension(100,30));
        version.setHorizontalAlignment(SwingConstants.RIGHT);
        //flow.setHgap(40);
        
        flow.addLayoutComponent("version", version);
        panel3.add(version);
    	
    }
    
    //Crea el panel donde están situados el checkbox y el botón para acceder a los usuarios
    public void crearPanel4(){
    
		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();
        jButton5 = Util.BotonImagen(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_menu_admin_salir"),"lib//cancelar.png");
   	 	jButton5.setFocusable(true);
        jButton5.getLabelTexto().setFont(new Font("Dialog", Font.BOLD, 10));
        jButton5.setMnemonic(KeyEvent.VK_E);
        jButton5.getLabelTexto().setDisplayedMnemonic(KeyEvent.VK_E);
        jButton5.getLabelImagen().setHorizontalAlignment(SwingConstants.RIGHT);
        jButton5.addMouseListener(new AccionRatonCreditosAux(jButton5,jButton5.getPresionado()));
        jButton5.getLabelTexto().getAccessibleContext().setAccessibleName(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_acceder"));
        jButton5.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_boton_acceder"));

        jButton5.setBackground(Color.white);
        jButton5.setBorder(new LineBorder(Color.black,2));
        jButton5.setPreferredSize(new Dimension(120,40));
        //jButton5.setMinimumSize(new Dimension( (int) Math.floor((float)(138*screenSize.width/1000)), (int) Math.floor((float)(77*screenSize.height/1000))));
        jButton5.addActionListener(new AccionCerrar(this,_frame));
   	 	jButton5.setColorMouseOver(Color.LIGHT_GRAY);
   	 	jButton5.setColorPresionado(Color.GRAY);
   	 	jButton5.addFocusListener(new AccionFocoCreditos(jButton5));

        jButton5.addMouseListener(new accionRaton(jButton5,jButton5.getPresionado()));

        check = new JCheckBox(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_check_creditos"), false);
   	 	check.setFocusable(true);
   	 	check.setMnemonic(KeyEvent.VK_N);
   	 	check.getAccessibleContext().setAccessibleName(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_checkbox_creditos"));
   	 	check.setToolTipText(ResourceBundle.getBundle("internacionalizacion/Etiquetas").getString("etiqueta_accesible_checkbox_creditos"));
        check.setBackground(Color.white);
        check.setFont(new Font("Dialog", Font.BOLD, 12));
        check.addItemListener(new AccionSeleccionarMostrarCreditos());
        if(Configuracion.instancia().getCreditos().equals("No")){
        	check.setSelected(true);
        }
    	FlowLayout flow = new FlowLayout();
    	panel4.setLayout(flow);
    	flow.addLayoutComponent("check", check);
    	panel4.add(check);
        flow.setHgap((int)700/7);

    	flow.addLayoutComponent("boton", jButton5);
    	panel4.setPreferredSize(new Dimension(screenSize.width,50));
    	panel4.add(jButton5);
    	
    }



	public BotonPersonalizado getSeleccionado() {
		return seleccionado;
	}



	public void setSeleccionado(BotonPersonalizado seleccionado) {
		this.seleccionado = seleccionado;
	}
        
    	
	
	
}
